package com.aaron.leetcode.lc03;

import java.util.HashMap;
import java.util.Map;

class Solution03_1 {
    Map<Character, Object> hashMap;

    int left = 0;

    //循环开始i=j，为了把开头的加入hashMap，所以设置right初始值为-1
    int right = -1;

    public int lengthOfLongestSubstring(String s) {

        if (null == s || s.length() == 0) {
            return 0;
        }

        int len = s.length();
        for (int i = 0; i < len; i++) {
            hashMap = new HashMap<>();
            int j = i;
            while (j < len) {
                if (hashMap.containsKey(s.charAt(j))) {
                    break;
                }
                hashMap.put(s.charAt(j), null);
                if (right - left < j - i) {
                    left = i;
                    right = j;
                }
                j++;
            }
        }

        return right - left + 1;
    }

    public static void main(String[] args) {
        Solution03_1 solution03_1 = new Solution03_1();
        String s = "123455";
        int ans = solution03_1.lengthOfLongestSubstring(s);
        System.out.println(ans);
    }

}